

package com.hazelcast.sql.impl.client;

import com.hazelcast.client.impl.protocol.ClientMessage;
import com.hazelcast.client.impl.protocol.codec.SqlMappingDdlCodec;
import com.hazelcast.instance.impl.Node;
import com.hazelcast.internal.nio.Connection;
import com.hazelcast.security.permission.ActionConstants;
import com.hazelcast.security.permission.MapPermission;
import com.hazelcast.sql.impl.InternalSqlService;

import java.security.Permission;

/**
 * SQL CREATE MAPPING DDL task.
 */
public class SqlMappingDdlTask extends SqlAbstractMessageTask<String> {

    public SqlMappingDdlTask(ClientMessage clientMessage, Node node, Connection connection) {
        super(clientMessage, node, connection);
    }

    @Override
    protected Object call() {
        InternalSqlService sqlService = nodeEngine.getSqlService();
        return sqlService.mappingDdl(parameters);
    }

    @Override
    protected String decodeClientMessage(ClientMessage clientMessage) {
        return SqlMappingDdlCodec.decodeRequest(clientMessage);
    }

    @Override
    protected ClientMessage encodeResponse(Object response) {
        return SqlMappingDdlCodec.encodeResponse((String) response);
    }

    @Override
    public String getServiceName() {
        return InternalSqlService.SERVICE_NAME;
    }

    @Override
    public String getDistributedObjectName() {
        return null;
    }

    @Override
    public String getMethodName() {
        return "mappingDdl";
    }

    @Override
    public Object[] getParameters() {
        return new Object[]{parameters};
    }

    @Override
    public Permission getRequiredPermission() {
        return new MapPermission(parameters, ActionConstants.ACTION_READ);
    }
}
